import pymysql
from dj030201.settings import *


class manageModel():
    def __init__(self):
        self.modules = []
        self.urls = []
        self.new_modules = []
        self.positionId = ''

    def get_models(self):
        mysql_db = pymysql.connect(host=DB_HOST,user=DB_USER,password=DB_PASSWORD,db=DB_NAME)
        cursour = mysql_db.cursor()
        sql = 'select * from adminmodules ORDER By Priority DESC'
        try:
            cursour.execute(sql)
            self.modules = cursour.fetchall()
        except Exception as e:
            print('程序出错了：' + str(e))
        finally:
            mysql_db.close()

    def change_modules(self):
        self.new_modules = []
        for module in self.modules:
            temp = []
            temp.append(module[0])
            temp.append(module[1])
            temp.append(module[2])
            temp.append(module[3])
            temp.append(module[4])
            self.new_modules.append(temp)

    def check_identity(self,username):
        self.positionId = ''
        mysql_db = pymysql.connect(host=DB_HOST, user=DB_USER, password=DB_PASSWORD, db=DB_NAME)
        cursour = mysql_db.cursor()
        sql = 'select PositionId from login where Username = "{}"'.format(username)
        try:
            cursour.execute(sql)
            self.positionId = cursour.fetchone()
        except Exception as e:
            print('程序出错了：' + str(e))
        finally:
            mysql_db.close()



if __name__ == '__main__':
    model = manageModel()
    model.check_identity('刘丽')
    print(type(model.positionId))